<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import = "java.util.*" %>
<%@ page import = "com.sinodata.bsm.common.vo.*" %>
<%@ page import = "com.sinodata.bsm.center.util.spring.SpringContextHolder" %>
<%@ page import = "com.sinodata.bsm.center.service.config.PortalService" %>
<%@page import="com.sinodata.bsm.center.user.UserUtil"%>
<%@ include file="../include/taglib.jsp"%>

<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragrma","no-cache");
response.setDateHeader("Expires",0);
String pageId = request.getParameter("pageId");

String userId = UserUtil.getInstance().getCurrentUser().getId();
PortalService portalService = SpringContextHolder.getBean(PortalService.class);
PagePortal portalPage = portalService.findPortalPageByUser(userId, pageId);
if(portalPage==null){
    portalPage = portalService.findPortalPageByUser("admin", pageId);
}
List<PageConf> pageList = portalService.findPageConfByPagePortal(portalPage.getId());
if(pageList==null){
    pageList = new ArrayList<PageConf>(0);
}
int colLength = portalPage.getColLength();
String[]  colWidth = new String[4];
colWidth[0]=portalPage.getCol1()+"%";
colWidth[1]=portalPage.getCol2()+"%";
colWidth[2]=portalPage.getCol3()+"%";
colWidth[3]=portalPage.getCol4()+"%";

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>portal</title>
    <meta http-equiv="refresh" content="60" />
    <%@ include file="../include/common.jsp"%>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/jquery.event.drag.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/jquery.event.drop.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/app/portal.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/progressbar/jquery.progressbar.min.js"></script>
     <script type="text/javascript" src="${pageContext.request.contextPath}/js/raty/js/jquery.raty.min.js"></script>

    <script type="text/javascript" >
    	var portalPage = '<%=pageId%>';
    </script>
    <link href="${pageContext.request.contextPath}/style/default/bsm/portal.css" charset="UTF-8" type="text/css" rel="stylesheet"/>
</head>
<body>
	   <table class="portal-wrapper">
        <tr>
        	<%
        		for(int i=0; i<colLength; i++)
        		{
        	%>
        		<td class="portal-col" id="col<%=i%>" width="<%=colWidth[i]%>">
        	<%
        			for(int j=0; j<pageList.size(); j++){
        			    PageConf conf = pageList.get(j);
        			    if(conf.getPosy()!=i){
        			        continue;
        			    }
        			    
        			    String pageModule = conf.getPageModule();
        			    PageModuleDef moduleDef = portalService.findPageModuleDefId(pageModule);
        			    String moduleTitle = moduleDef.getTitle();
        			    
        			    Long confId = conf.getId();
        			    String jspage = "module/"+conf.getPageModule()+".jsp";
        			    String title = conf.getTitle();
        			    String paramPage = conf.getParamPage();
        			    String param = conf.getParams();
        			    if(param==null){ param = "";}
        	%>
        			<div class="box portal" id="divWrap_<%=confId %>">
                    	<h2 class="handle">
                    	<span style="float:left;"><%=title %></span>
                    	<span>
                    	    <a onclick="hiddenIt('<%=confId %>');" title="关闭" class="close" ></a>
                    	    <%
                    	    	if(paramPage!=null){
                    	    		
                    	    %>
	                    	<a onclick="showParamPage('<%=confId %>','<%=paramPage %>','<%=moduleTitle %>')" title="编辑" class="edit"></a>
	                    	<%
        						}
                    	    %>
	                    	
	                    	<a onclick="toggleContent('<%=confId %>')" title="展开/缩进" class="edit stretch"></a> 	   	                    	
                    	</span>
                    	</h2>
                    	<div class="selectable" id="divContent_<%=confId %>">
                       		<jsp:include page="<%=jspage%>">
                       			<jsp:param name="args" value="<%=param %>" ></jsp:param>
                       		</jsp:include>
                    	</div>
                	</div>
        	<% 	
        			}
      			if(i==colLength-1){
            	%>
            			<div class="box portal">
                        	<h2 class="handle" >页面维护</h2>
                        	<div class="selectable ymwh" >
                           			<a name="bt" value="添加组件"  onclick="addComp('<%=pageId %>');" herf="#" >添加组件 </a>
                           			<a type="button" name="bt" value="编辑布局"   onclick="confLayout('<%=portalPage.getId() %>');" herf="#">编辑布局</a>
                        	</div>
                    	</div>
            	<% 		    
            			    
            			}
        	%>		
            	</td>
        	<% 	    
        		}
        	
        	%>
        </tr>
    </table>
    
 </body>
</html>